<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use App\Models\Relations\CommonTrait;
use App\Models\Relations\UserInfoTrait;
class BbsQuestion extends Model
{
    use SoftDeletes,CommonTrait,UserInfoTrait;
    
    protected $table="bbs_question";
    
    protected $fillable = ['id','title','detail','publish_uid','category_id','answer_count',
           'answer_users','view_count','focus_count','comment_count','agree_count','against_count','best_answer',
            'has_attach','client_ip','last_answer','sort','thanks_count','question_content_full_text'
    ];
    
    protected $dates = ['deleted_at'];

    /**
     * 问题一对多的关系映射
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function answers()
    {
        return $this->hasMany('App\Models\BbsAnswer', 'question_id');
    }

    /**
     * 根据问题获取分类模型
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function getBbsCatByQuestion()
    {
        return $this->belongsTo('App\Models\BbsCategory', 'category_id');
    }

    public function scopePopular($query)
    {
        return $query->where('category_id', '=', 1);
    }

    public function scopeOfPublishUid($query, $qt)
    {
        return $query->wherePublishUid($qt);
    }
    
    public function category()
    {
       return $this->hasOne('App\Models\BbsCategory','id','category_id');
    }
    
    public  function cateuse()
    {
        return $this->hasOne('App\User','id','publish_uid');
    }
    
    public function comment()
    {
        return $this->hasMany('App\Models\BbsQuestionComment','question_id','id');
    }

    


}
